<?php

class tutorapply extends Controller {

	function tutorapply()
	{
		parent::Controller();	
	}
	
	function index()
	{
		$data['form_status'] = 'add';
		$this->load->view('f_tutorapply', $data);
	}
	
	function save() 
	{
		$this->load->model('TutorModel');
		$this->load->model('TutorSchoolModel');
		$data = array();
		$title = $this->input->post('radTitle');
		$titleOther = $this->input->post('txtTitleOther');
		if($title != 'อื่นๆ') {
			$data['title'] = $title;
		} else {
			$data['title'] = $titleOther;
		}
		$data['first_name_th'] = $this->input->post('txtFirstNameTh');
		$data['last_name_th'] = $this->input->post('txtLastNameTh');
		$data['nick_name'] = $this->input->post('txtNickName');
		$data['first_name_en'] = $this->input->post('txtFirstNameEn');
		$data['last_name_en'] = $this->input->post('txtLastNameEn');
		$data['citizen_id'] = $this->input->post('txtCitizenId') ? $this->input->post('txtCitizenId') : null;
		$data['comment'] = $this->input->post('txtComment') ? $this->input->post('txtComment') : null;
		$data['email'] = $this->input->post('txtEmail') ? $this->input->post('txtEmail') : null;    
	    $data['telephone_home'] = $this->input->post('txtTel') ? $this->input->post('txtTel') : null;
	    $data['mobile01'] = $this->input->post('txtMobile01') ? $this->input->post('txtMobile01') : null;
	    
		$netMobile = $this->input->post('selNetMobile01') ? $this->input->post('selNetMobile01') : null;
		$netMobileOther = $this->input->post('txtNetMobile01') ? $this->input->post('txtNetMobile01') : null;
		if($netMobile != 'อื่นๆ (โปรดระบุ)') {
			$data['mobile01_network'] = $netMobile;
		} else {
			$data['mobile01_network'] = $netMobileOther;
		}
	    
		$data['mobile02'] = $this->input->post('txtMobile02') ? $this->input->post('txtMobile02') : null;
		$netMobile = $this->input->post('selNetMobile02') ? $this->input->post('selNetMobile02') : null;
		$netMobileOther = $this->input->post('txtNetMobile02') ? $this->input->post('txtNetMobile02') : null;
		if($netMobile != 'อื่นๆ (โปรดระบุ)') {
			$data['mobile02_network'] = $netMobile;
		} else {
			$data['mobile02_network'] = $netMobileOther;
		}
		
	    $data['add_room_no'] = $this->input->post('txtRoomNo') ? $this->input->post('txtRoomNo') : null;
	    $data['add_home_no'] = $this->input->post('txtHomeNo') ? $this->input->post('txtHomeNo') : null;
	    $data['add_building_name'] = $this->input->post('txtBuilding') ? $this->input->post('txtBuilding') : null;
	    $data['add_moo'] = $this->input->post('txtMoo') ? $this->input->post('txtMoo') : null;
	    $data['add_soi'] = $this->input->post('txtSoi') ? $this->input->post('txtSoi') : null;
	    $data['add_road'] = $this->input->post('txtRoad') ? $this->input->post('txtRoad') : null;
	    $data['add_distinct'] = $this->input->post('txtDistinct') ? $this->input->post('txtDistinct') : null;
	    $data['add_area'] = $this->input->post('txtArea') ? $this->input->post('txtArea') : null;
	    $data['add_province'] = $this->input->post('txtProvince') ? $this->input->post('txtProvince') : null;
	    $data['add_post_code'] = $this->input->post('txtPostCode') ? $this->input->post('txtPostCode') : null;
	    $data['add_note'] = $this->input->post('txtAddNote') ? $this->input->post('txtAddNote') : null;
	    $data['source'] = 'C';
	    
		$id = $this->TutorModel->addFromC($data, $this->input->post('txtBirthday'));
		$scArray = array('tutor_id' => $id, 'shool_id' => '1');
		$this->TutorSchoolModel->add($scArray);
		$d['id'] = $id;
		
		$this->load->view('f_tutorapply2', $d);
	}
	
	function update()
	{
		$id = $this->input->post('txtID');
		if($id != null) {
			$this->load->model('TutorModel');
			$data['tutor_id'] = $id; 
			$data['edu_status'] = $this->input->post('rdEduStatus') ? $this->input->post('rdEduStatus') : null;
			$data['edu_current_level'] = $this->input->post('studyingLevel') ? $this->input->post('studyingLevel') : null;
			$data['edu_current_university'] = $this->input->post('studyingUniversity') ? $this->input->post('studyingUniversity') : null;
			$data['edu_current_department'] = $this->input->post('studyingMajor') ? $this->input->post('studyingMajor') : null;
			$data['edu_current_student_id'] = $this->input->post('studyingID') ? $this->input->post('studyingID') : null;
			$data['edu_current_class'] = $this->input->post('studyingClass') ? $this->input->post('studyingClass') : null;
			$data['edu_current_GPA'] = $this->input->post('studyingGPA') ? $this->input->post('studyingGPA') : null;
			$data['edu_pratom_school'] = $this->input->post('pratomSchool') ? $this->input->post('pratomSchool') : null;
			$data['edu_pratom_major'] = $this->input->post('pratomMajor') ? $this->input->post('pratomMajor') : null;
			$data['edu_pratom_student_id'] = $this->input->post('pratomID') ? $this->input->post('pratomID') : null;
			$data['edu_pratom_GPA'] = $this->input->post('pratomGPA') ? $this->input->post('pratomGPA') : null;
			$data['edu_mo_tom_school'] = $this->input->post('tonSchool') ? $this->input->post('tonSchool') : null;
			$data['edu_mo_tom_major'] = $this->input->post('tonMajor') ? $this->input->post('tonMajor') : null;
			$data['edu_mo_tom_student_id'] = $this->input->post('tonID') ? $this->input->post('tonID') : null;
			$data['edu_mo_tom_GPA'] = $this->input->post('tonGPA') ? $this->input->post('tonGPA') : null;
			$data['edu_mo_pay_school'] = $this->input->post('paySchool') ? $this->input->post('paySchool') : null;
			$data['edu_mo_pay_major'] = $this->input->post('payMajor') ? $this->input->post('payMajor') : null;
			$data['edu_mo_pay_student_id'] = $this->input->post('payID') ? $this->input->post('payID') : null;
			$data['edu_mo_pay_GPA'] = $this->input->post('payGPA') ? $this->input->post('payGPA') : null;
			$data['edu_bachelor_university'] = $this->input->post('bSchool') ? $this->input->post('bSchool') : null;
			$data['edu_bachelor_major'] = $this->input->post('bMajor') ? $this->input->post('bMajor') : null;
			$data['edu_bachelor_student_id'] = $this->input->post('bID') ? $this->input->post('bID') : null;
			$data['edu_bachelor_GPA'] = $this->input->post('bGPA') ? $this->input->post('bGPA') : null;
			
			$data['edu_master_university'] = $this->input->post('mSchool') ? $this->input->post('mSchool') : null;
			$data['edu_master_major'] = $this->input->post('mMajor') ? $this->input->post('mMajor') : null;
			$data['edu_master_student_id'] = $this->input->post('mID') ? $this->input->post('mID') : null;
			$data['edu_master_GPA'] = $this->input->post('mGPA') ? $this->input->post('mGPA') : null;
			
			$data['edu_doctor_university'] = $this->input->post('dSchool') ? $this->input->post('dSchool') : null;
			$data['edu_doctor_major'] = $this->input->post('dMajor') ? $this->input->post('dMajor') : null;
			$data['edu_doctor_student_id'] = $this->input->post('dID') ? $this->input->post('dID') : null;
			$data['edu_doctor_GPA'] = $this->input->post('dGPA') ? $this->input->post('dGPA') : null;
			
			$data['teach01_subject'] = $this->input->post('txtTeach01Subject') ? $this->input->post('txtTeach01Subject') : null;
			$data['teach01_class'] = $this->input->post('txtTeach01') ? $this->input->post('txtTeach01') : null;
			$data['teach01_inter'] = $this->input->post('txtTeach01Inter') ? $this->input->post('txtTeach01Inter') : null;
			$data['teach02_subject'] = $this->input->post('txtTeach02Subject') ? $this->input->post('txtTeach02Subject') : null;
			$data['teach02_class'] = $this->input->post('txtTeach02') ? $this->input->post('txtTeach02') : null;
			$data['teach02_inter'] = $this->input->post('txtTeach02Inter') ? $this->input->post('txtTeach02Inter') : null;
			$data['teach03_subject'] = $this->input->post('txtTeach03Subject') ? $this->input->post('txtTeach03Subject') : null;
			$data['teach03_class'] = $this->input->post('txtTeach03') ? $this->input->post('txtTeach03') : null;
			$data['teach03_inter'] = $this->input->post('txtTeach03Inter') ? $this->input->post('txtTeach03Inter') : null;
			$data['teach04_subject'] = $this->input->post('txtTeach04Subject') ? $this->input->post('txtTeach04Subject') : null;
			$data['teach04_class'] = $this->input->post('txtTeach04') ? $this->input->post('txtTeach04') : null;
			$data['teach04_inter'] = $this->input->post('txtTeach04Inter') ? $this->input->post('txtTeach04Inter') : null;
			$data['teach05_subject'] = $this->input->post('txtTeach05Subject') ? $this->input->post('txtTeach05Subject') : null;
			$data['teach05_class'] = $this->input->post('txtTeach05') ? $this->input->post('txtTeach05') : null;
			$data['teach05_inter'] = $this->input->post('txtTeach05Inter') ? $this->input->post('txtTeach05Inter') : null;
			$data['teach06_subject'] = $this->input->post('txtTeach06Subject') ? $this->input->post('txtTeach06Subject') : null;
			$data['teach06_class'] = $this->input->post('txtTeach06') ? $this->input->post('txtTeach06') : null;
			$data['teach06_inter'] = $this->input->post('txtTeach06Inter') ? $this->input->post('txtTeach06Inter') : null;
			
			$data['teach_area'] = $this->input->post('txtArea') ? $this->input->post('txtArea') : null;
			
			$this->TutorModel->updateFromC($data);
			$msg['success'] = "ได้รับข้อมูลเรียบร้อยแล้วค่ะ ทางโรงเรียนจะติดต่อกลับไปเร็วที่สุดค่ะ";
			$msg['form_status'] = 'add';
			$this->load->view('f_tutorapply', $msg);
		} else {
			$this->index();
		}
	}
}
?>